<?php
require_once APP . '/application/admincontrollers/AdminAction.php';
require_once APP  . '/application/models/UserModel.php';
require_once APP  . '/application/models/PaylogModel.php';
require_once APP . '/application/models/Util.php';

/**
 * 平台设置
 * @package admin
 */
class PayController extends AdminAction
{
    
    public function init()
    {
    }
	
    public function listAction()
    {
    	$nowp = $this->getParam ('nowp', 1);
        $per_page = 20;

        $image_obj = new PaylogModel($this->db);
        $result = $image_obj->fetchAll($nowp, $per_page);

        $this->view->list = $result['list'];
        $this->view->page = $result['page'];
    }
    
    
    public function userAction()
    {
    	$uid = (int)$this->getParam("uid", 0);
    	$pay = (int)$this->getParam("pay", 0);
    	
    	$beforecash = $this->db->fetchOne("select cash from user where uid=$uid");
    	$this->db->query("update user set pay=pay+$pay, cash=cash+$pay where uid=$uid");
    	$ret = $this->db->affectRows();
    	
    	if ($ret){
    		$this->view->message = "操作成功,修改值：" . $pay;
			
			$param["uid"] = $uid;
			$param["pay"] = $pay;
			$param["channel"] = "手工充值";
			$param["GameCash"] = $pay;
			$param["BeforeCash"] = $beforecash;
			$param["IP"] = Util::getip(true);
			$param["CreateTime"] = date("Y-m-d H:i:s");
			$param["UpdateTime"] = date("Y-m-d H:i:s");
			$param["PlatFormOrderId"] = "";
			$param['AlreadyPay'] = 1;

    		// 增加操作日志
    		$model = new PaylogModel($this->db);
    		$model->add($param);
    	}
    	
    	$this->view->uid = $uid;
    }
}